import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import qs from 'qs';
import router from './router'
import store from './store/store.js'
import 'amfe-flexible';
import VueLazyload from 'vue-lazyload'
// 1. 引入公共项
import './assets/style/reset.css'
import './assets/style/border.css'
import './assets/style/common.less'
// 2. 使用fastclick
import fastClick from 'fastclick'

fastClick.attach(document.body)

// import Vconsole from "vconsole";
//
// let vConsole = new Vconsole();
// Vue.use(vConsole);

import wx from "weixin-jsapi";

Vue.use(wx);

// 全局组件

import {
    Dialog, Toast, NavBar, Icon, Button, Checkbox, CheckboxGroup, SubmitBar,
    SwipeCell, Stepper, Cell, CellGroup, Card, Badge,
    BadgeGroup,
    Tab, Tabs
} from 'vant';

Vue.use(Dialog)
    .use(Toast)
    .use(Button).use(SubmitBar).use(Checkbox).use(CheckboxGroup).use(SwipeCell)
    .use(Icon).use(Cell).use(CellGroup).use(Card).use(BadgeGroup).use(Badge).use(Tab).use(Tabs);
Vue.use(NavBar);
Vue.use(Stepper);

import Directives from './utils/directives';

Vue.use(Directives); //注册全局指令


// import common from './utils/common'
// Vue.prototype.common = common
Vue.prototype.$axios = axios;
Vue.prototype.$qs = qs;
/* axios.defaults.baseURL = 'http://aqjx.xyz/index.php/api/'; */
axios.defaults.baseURL = 'http://192.168.31.135:8080/api/';
axios.interceptors.response.use((response) => {
    const data = response.data;
    switch (data.code) {
        case 200:
            return data;
        case 300:
            Toast("登录信息过期,请重新登录");
            setTimeout(() => {
                router.replace("/login");
            }, 500);
            break;
        case 400:
            router.push({path: '/'});
            Toast(data.msg);
            break;
        default:
            Toast("系统错误");
            break;
    }
});

Vue.config.productionTip = false;

new Vue({
    router,
    store,
    render: h => h(App),

    // beforeMount() {
    //   this.$store.commit('updateUserInfo')
    // }
}).$mount('#app')

Vue.use(VueLazyload, {
    preLoad: 1.3,
    loading: require('@/assets/imgList/loading.gif'),//设置加载中时要显示的图片
    error: require('@/assets/imgList/none.jpg'),
    attempt: 1
});